﻿using System;
using System.Data;
using System.Xml;
using VitCode.BaseDataPageCreator.Setting;
using VitCode.Castle.DataAccess;
using VitCode.Castle.Helper;
using VitCode.Castle.Management;
using VitCode.Web.UI;
using VitCode.Web.UI.WebControls;

namespace AMS.Web.UserControls
{
    public partial class AssetWoBillInfoCtl : System.Web.UI.UserControl
    {
        private ObjXmlReader m_XmlReader;
        BaseDataManager m_Help = new BaseDataManager();
        public string KeyProVal
        {
            get { return hdnKeyProVal.Value; }
            set { hdnKeyProVal.Value = value; }
        }

        public string KeyProName
        {
            get { return hdnKeyProName.Value; }
            set { hdnKeyProName.Value = value; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            pgList.DataSourceDelegate = new PaginationGrid.GridDataSourceDelegate(BindList);
           
        }
 

        private object BindList()
        {
            string strCondition = " where AssetInfoId ='" + KeyProVal + "'";
            DataSet ds;
            var acc = new BaseDataAccess();
            var sqlHelper = new SqlHelper();
            string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "AssetQuery\\ProSetting.xml";
            m_XmlReader = new ObjXmlReader(xmlPath);
            XmlNode node = m_XmlReader.GetXmlNode("Setting/AssetWoInfoSql");
            if (node != null)
            {
                string sql = m_XmlReader.GetNodeAttributeValue(node, "sql", true);
                sql = sql.Replace("\r\n", " ").Replace("\t", " ");
                try
                {
                    ds = sqlHelper.ExecuteDataSet(acc.Session, sql + strCondition);
                }
                finally
                {
                    acc.CloseSession();
                }
                return ds.Tables[0];
            }
            return null;
        }


        internal void BindData()
        {
            pgList.BindGrid();
        }

        protected void pgList_OnGridItemSelect(object sender, PaginationGridItemSelectArgs e)
        {
            string val = e.SelectedDataKeyValue;
            string sql = "select TypeName from AmsWorkBill_WoInfo where Id='" + val + "'";
            var dt = m_Help.GetDataTableBySql(sql);
            if(dt != null && dt.Rows.Count > 0)
            {
                 string strClassName = dt.Rows[0][0].ToString() + "Sql";
                 var win = new Window(Page, "工单明细") { Height = 700, Width = 1000, Scrollbars = true, Status = true };
                 win.ShowModalDialog("../AssetQuery/WorkBillInfoDetail.aspx?ClassName=" + strClassName + "&WorkBillId=" + val, new string[] { "hdCheckInfo" });
            }
           
        }
    }
}